<?php
require_once   BaseUtil::getModulePath("base")  .  '/validate/Unique.php';

class CampusForm extends Zend_Form 
{
	public function __construct($provinces, $campus = null){
		$translate = Zend_Registry::get('Zend_Translate');
		
		$this->setMethod('post');
		$this->setName('Campus_Form');
		
		$campusName = new Zend_Form_Element_Text('campus_name');
		$campusName->setLabel($translate->_('campusName'));
		$campusName->addFilter("StringTrim");
		$campusName->setRequired(true);
		
		$validUnique = new MyValid_Unique();
		$validUnique->setTableName('agent_campuses');
		$validUnique->setFieldName('area_name');
		if(!empty($campus['id'])){
			$validUnique->setId($campus['id']);
		}
		
		$campusName->addValidator($validUnique);
		
		$campusComment = new Zend_Form_Element_Textarea('comment');
		$campusComment->setLabel($translate->_('campusComment'));
		$campusComment->setAttribs(array("rows" => 3, "cols" => 30));
		$campusComment->addFilter("StringTrim");
		
		$provinceArr = array(""=>$translate->_('selectLabel')); 
		foreach($provinces as $province){
			$provinceArr[$province['id']] = $province['title'];
		}
		
		$areaName = new Zend_Form_Element_Select('area_dict');
		$areaName->setLabel($translate->_('areaName'));
		$areaName->addMultiOptions($provinceArr);
		$areaName->setRequired(true);
		
		$selectArr = array("1"=>$translate->_( "yesLabel" ),"0"=>$translate->_( "noLabel" ));
		
		$visible = new Zend_Form_Element_Select('visible');
		$visible->setLabel($translate->_('visible'));
		$visible->addMultiOptions($selectArr);
		
		$showInOrder = new Zend_Form_Element_Select('show_in_order');
		$showInOrder->setLabel($translate->_('showInOrder'));
		$showInOrder->addMultiOptions($selectArr);
		
		if($campus){
			$campusName->setValue($campus['area_name']);
			$campusComment->setValue($campus['comment']);
			$areaName->setValue($campus['area_dict_id']);
			$visible->setValue($campus['visible']);
			$showInOrder->setValue($campus['show_in_order']);
		}
		
		$elements = array($campusName,$campusComment,$areaName,$visible,$showInOrder);
		$this->addElements($elements);
        $this->setElementDecorators(array(
            'ViewHelper',
            array(array('div' => 'HtmlTag'), array('tag' => 'div',"class" => "form_element")),
        ));
	
	}
	
}
?>